<?php
/*
 * Created on Feb 24, 2008
 * @author max
 */
include_once(dirname(__FILE__).'/../database/dbShifts.php');
include_once(dirname(__FILE__).'/../database/dbDates.php');
class testdbShifts extends UnitTestCase {
  function testdbShiftsModule() {
	$s1=new Shift("02-25-08-night",3, null, "", "");
	$this->assertTrue(insert_dbShifts($s1));
	$this->assertTrue(delete_dbShifts($s1));
	$s2=new Shift("02-25-08-15-18",3, null, "", "");
	$this->assertTrue(insert_dbShifts($s2));
	$this->assertTrue(select_dbShifts("02-25-08-15-18")!==null);
	$s2=new Shift("02-25-08-15-18",2, null, "", "");
	$this->assertTrue(update_dbShifts($s2));
	$shifts[] = $s2;
$this->assertTrue(get_shift_name_from_id($s2->get_id())=="Monday, February 25th, 2008 from 3pm to 6pm");
// test moving a shift around
       $s3 = new Shift("02-25-08-12-15",2, null, "", "");
       $shifts[] = $s3;
       $this->assertTrue(insert_dbShifts($s3));
       $d = new RMHdate("02-25-08",$shifts,"","");
       $this->assertTrue(insert_dbDates($d));
	   $this->assertTrue(move_shift($s3, 9, 12));
       $this->assertTrue($s3->get_start_time()==9);
$this->assertTrue(get_shift_name_from_id($s3->get_id())=="Monday, February 25th, 2008 from 9am to 12pm");
	   $this->assertFalse(move_shift($s3, 12, 16));
       $s3->set_start_end_time(9, 12);
	   $this->assertTrue(delete_dbShifts($s3));

	$this->assertTrue(delete_dbShifts($s2));
	$this->assertTrue(delete_dbDates($d));
        
        
        $s1 = new Shift("01-20-00-8-12", 3, null, "", "");
        $this->assertTrue(selectDateVacancies_dbShifts("01-20-00")!==false);
        $this->assertTrue(selectDateRangeVacancies_dbShifts("01-20-00")!==false);
        $this->assertTrue(get_avg_vacancies_in_date("01-20-00")==3);
        $this->assertTrue(get_avg_vacancies_in_date_range(array("01-20-00"))==3);
        $this->assertTrue(get_sum_vacancies_in_date("01-20-00")==3);
        $this->assertTrue(get_sum_vacancies_in_date_range(array("01-20-00"))==3);
	echo ("testdbShifts complete");
  }
}
?>
